home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / USBModem / Modem.h next >
Encoding:
C/C++ Source or Header  |  2000-09-25  |  5.1 KB  |  198 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Modem.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #ifndef    _MODEM_
  13. #define    _MODEM_
  14.  
  15. #include <Serial.h>
  16. #include <USB.h>
  17.  
  18. #include "SerialShim.h"
  19.  
  20. // Debug stuff
  21.  
  22. #define DebugOn        0                        // This is the master switch (On > 0)
  23. #define LogOn        0                        // On > 0 (DebugOn must also be on)
  24. #define LogBug        0                        // On > 0 (DebugOn and LogOn (to log data) must also be on) - dumps to the debugger
  25. #define FullTrace    0                        // On > 0 Be careful with this as it traces everything (DebugOn must also be on)
  26.  
  27. #if (DebugOn > 0)
  28. #define SLevel        4                        // Status level for USB Expert Log
  29. #else
  30. #define SLevel        5                        // Status level for USB Expert Log
  31. #endif
  32.  
  33. #if (DebugOn > 0)
  34. #define DebugMessage(s)        DebugStr(s)
  35. #else
  36. #define DebugMessage(s)
  37. #endif
  38.  
  39. #if (DebugOn > 0)
  40. #define Bugon        " - Debug"
  41. #else
  42. #define Bugon
  43. #endif
  44.  
  45. #if ((DebugOn > 0) && (LogOn > 0))
  46. #define LogData(x, y, z)    USBLogData(x, y, z)
  47. #else
  48. #define LogData(x, y, z)
  49. #endif
  50.  
  51. #if (DebugOn > 0)
  52.     #if (LogBug > 0)
  53.         #define TraceMessage(x, s)    {if (FullTrace > 0) DebugStr(s); else if (x) DebugStr(s);}
  54.     #else
  55.         #define TraceMessage(x, s)    {if (FullTrace > 0) USBStatus(SLevel, 0, s, 0); else if (x) USBStatus(SLevel, 0, s, 0);}
  56. //        #define TraceMessage(x, s)    {if (FullTrace > 0) USBExpertStatusLevel(SLevel, 0, s, 0); else if (x) USBExpertStatusLevel(SLevel, 0, s, 0);}
  57. //        #define TraceMessage(x, s)    {if (FullTrace > 0) USBExpertStatus(0, s, 0); else if (x) USBExpertStatus(0, s, 0);}
  58.     #endif
  59. #else
  60.     #define TraceMessage(x, s)
  61. #endif
  62.  
  63. #if (DebugOn > 0)
  64.     #if (LogBug > 0)
  65.         #define StatusMessage(a, s, c)    DebugStr(s)
  66.     #else
  67.         #define StatusMessage(a, s, c)    USBStatus(SLevel, a, s, c)
  68. //        #define StatusMessage(a, s, c)    USBExpertStatusLevel(SLevel, a, s, c)
  69. //        #define StatusMessage(a, s, c)    USBExpertStatus(a, s, c)
  70.     #endif
  71. #else
  72.     #define StatusMessage(a, s, c)    USBStatus(SLevel, a, s, c)
  73. //    #define StatusMessage(a, s, c)    USBExpertStatusLevel(SLevel, a, s, c)
  74. //    #define StatusMessage(a, s, c)
  75. #endif
  76.  
  77. #if (DebugOn > 0)
  78. #define noteError(s)    sp->errorString = s;
  79. #else
  80. #define noteError(s)
  81. #endif
  82.  
  83. //    Change these for other modems etc.
  84.  
  85. #define kUSBVendor        0x0000                            // None
  86. #define kUSBProduct     0x0000                            // None
  87. #define kModemName        "\pUSB Modem"                    // Name registry name
  88.                                                         // The following three names will be made unique
  89.                                                         // by the shim if they are not
  90. #define kCRMName         "\pUSB Modem "                    // CRM name
  91. #define kDRVRInName        "\p.UIn"                        // .In driver name
  92. #define kDRVROutName    "\p.UOut"                        // .Out driver name
  93.  
  94. //  USB stuff 
  95.  
  96. #define k5DataBits                5
  97. #define k6DataBits                6
  98. #define k7DataBits                7
  99. #define k8DataBits                8
  100.  
  101. #define k1StopBit                0
  102. #define k15StopBits                1
  103. #define k2StopBits                2
  104.  
  105. #define kNoParity                0
  106. #define kOddParity                1
  107. #define kEvenParity                2
  108. #define kMark                    3
  109. #define kSpace                    4
  110.  
  111. #define kDTROff                    0
  112. #define kRTSOff                    0
  113. #define kDTROn                    1
  114. #define kRTSOn                    2
  115.  
  116. #define kBreakOn                0xFFFF
  117. #define kBreakOff                0
  118.  
  119. #define kUSBDCD                    0x01
  120. #define kUSBDSR                    0x02
  121. #define kUSBBreakDetect            0x04
  122. #define kUSBRingSignal            0x08
  123. #define kUSBFramingErr            0x10
  124. #define kUSBParityErr            0x20
  125. #define kUSBHwOverRunErr        0x40
  126.  
  127. typedef struct{
  128.     UInt16    DTERate1;
  129.     UInt16    DTERate2;
  130.     UInt8    CharFormat;
  131.     UInt8    ParityType;
  132.     UInt8    DataBits;
  133.     } LineParms;
  134.     
  135. enum{
  136.     kSendEncapsulatedCommand = 0,
  137.     kGetEncapsulatedResponse = 1,
  138.     kSetCommFeature = 2,
  139.     kGetCommFeature = 3,
  140.     kClearCommFeature = 4,
  141.     kSetLineCoding = 0x20,
  142.     kGetLineCoding = 0x21,
  143.     kSetControlLineState = 0x22,
  144.     kSendBreak = 0x23,
  145.     };
  146.     
  147. enum{
  148.     kResponseAvailable = 1,
  149.     kSerialState = 0x20,
  150.     };
  151.  
  152. enum
  153. {
  154.     kBuiltInBufferSize    =    4096,
  155.     kMaxBaudRate        =    115200,
  156. };
  157.  
  158. // Global data structure
  159.  
  160. typedef    struct    ShimSerialGlobals
  161. {
  162.     //    input buffers
  163.     UInt8                builtInBuffer[kBuiltInBufferSize];    //    default input buffer
  164.     UInt8                 *inBufPtr;                            //    pointer to current input buffer
  165.     UInt16                inBufLen;                            //    length of said buffer
  166.     UInt16                inBufStartIndex;                    //    circular queue indexes
  167.     UInt16                inBufEndIndex;
  168.     
  169.     //    serial driver state
  170.     
  171.     UInt8                xOnOffChar;            //    an xon or xoff char to be sent
  172.     UInt8                lenParStop;            //    length, parity, stop bits
  173.     UInt8                peChar;                //    parity error replacement character
  174.     UInt8                peAltChar;            //    parity error alternate replacement character
  175.     UInt32                baudRate;            //    actual baud rate value i.e. 19200
  176.     SerShk                serShk;                //    handshake record (see inside mac, vol ii, serial drivers
  177.     SerStaRec            serStat;            //    serial status record (see inside mac, vol ii, serial drivers)
  178.     
  179.     //    miscellaneous
  180.     
  181.     ParmBlkPtr            pbIn;                //    current prime read request
  182.     ParmBlkPtr            pbOut;                //    current prime write request
  183.     ShimRefNum            ShimRef;            //    save the shim's reference number
  184.     Boolean                openSession;        //  only allow one open session
  185.     CFragConnectionID    ConnID;                //    connection to the shim
  186.     
  187.     //    Install and remove CFM routines
  188.     
  189.     OSErr                 (*ShimInstall) (SerialShimInterface IntBlk, ShimRefNum *ref);
  190.     OSErr                 (*ShimRemove) (ShimRefNum ref, Boolean forced);
  191.     void                 (*ShimComplete) (ShimRefNum ref, IOParam *pb);
  192.  
  193. } ShimSerialGlobals;
  194.  
  195. extern    ShimSerialGlobals    *gGlobals;
  196.  
  197. #endif
  198.